	# Autoloading.pm
	package Autoloading;
	use strict;
	
	sub new {return bless {}, shift}
	
	sub _property ($$;$) {
	   my ($self, $attr, $value) = @_;
	
	   if ($value) {
	      my $oldv = $self->{$attr}{$value};
	      $self->{$attr} = $value;
	      return $oldv;
	   }
	
	   return $self->{$attr};
	}
	
	sub AUTOLOAD {
	   our $AUTOLOAD;
	
	   my $attr;
	   $AUTOLOAD =~ /([^:]+)$/ and $attr = $1;
	
	   # abort if this was a destructor call
	   return if $attr eq 'DESTROY';
	
	   # otherwise, invent a method and call it
	   eval "sub $attr {return shift->_property('$attr', \@_);}";
	   shift->$attr(@_);
	}
	
	1;
